import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.net.URL;

import javax.imageio.ImageIO;

public class drawClass {
	heli h;
	haupt p;
	wolke w;
	gegner ge;
	int level;
	public Image img;
	public Image lvl1 = Toolkit.getDefaultToolkit().getImage("src/bgLvl1.jpg");
	public Image lvl2 = Toolkit.getDefaultToolkit().getImage("src/bgLvl2.jpg");
	public Image lvl3 = Toolkit.getDefaultToolkit().getImage("src/bgLvl3.jpg");
	public Image lvl4 = Toolkit.getDefaultToolkit().getImage("src/bgLvl4.jpg");

	public drawClass(haupt parent, int lvl) {
		BufferedImage[] heli = this.loadPics("heli.gif", 4);
		BufferedImage[] wolke = this.loadPics("cloud.gif", 1);

		this.p = parent;
		h = new heli(heli, p.getWidth() / 2, p.getHeight() / 2);
		w = new wolke(5, p.getWidth(), p.getHeight(), 5, 50, wolke);

		BufferedImage[] ufo = this.loadPics("ufo.gif", 1);
		ge = new gegner(5, p.getWidth(), p.getHeight(), 5, 10, ufo);

		this.level = lvl;

	}

	public void drawObject(Graphics g) {
		// super.paintComponent(g);
		// g.drawString(""+level,100,100);
		bgLevel();
		g.drawImage(img, 0, 0, null);
		w.drawObjects(g);
		h.drawObject(g);
		ge.drawObjects(g);
	}

	private BufferedImage[] loadPics(String path, int anzahl) {
		BufferedImage[] bild = new BufferedImage[anzahl];
		BufferedImage source = null;

		URL url = getClass().getClassLoader().getResource(path);
		try {
			source = ImageIO.read(url);
		} catch (Exception e) {
		}

		for (int x = 0; x < anzahl; x++) {
			bild[x] = source.getSubimage(x * source.getWidth() / anzahl, 0,
					source.getWidth() / anzahl, source.getHeight());
		}

		return bild;
	}

	public void bgLevel() {
		switch (this.level) {
		case 1:
			img = lvl1;
			break;
		case 2:
			img = lvl2;
			break;
		case 3:
			img = lvl3;
			break;
		case 4:
			img = lvl4;
			break;
		default:
			img = lvl1;
			break;
		}
	}
}